package com.tanhua.server.controller;

import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.RecommendUserVo;
import com.tanhua.model.vo.TodayBestVo;
import com.tanhua.server.service.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.Path;
import java.util.List;
import java.util.Map;

/**
 * 交友模块控制层
 */
@RestController
@RequestMapping("/tanhua")
public class TanhuaController {

    @Autowired
    private TanhuaService tanhuaService;

    /**
     * 今日佳人
     * @return
     */
    @RequestMapping(value = "/todayBest", method = RequestMethod.GET)
    public ResponseEntity todayBest() {
        TodayBestVo todayBestVo = tanhuaService.todayBest();
        return ResponseEntity.ok(todayBestVo);
    }


    /**
     * 推荐用户分页列表数据
     * @return
     */
    @RequestMapping(value = "/recommendation", method = RequestMethod.GET)
    public ResponseEntity findPageRecommendUser(RecommendUserVo recommendUserVo) {
        PageResult<TodayBestVo> bestVoPageResult = tanhuaService.findPageRecommendUser(recommendUserVo);
        return ResponseEntity.ok(bestVoPageResult);
    }


    /**
     * 佳人信息查询详情
     * @return
     */
    @RequestMapping(value = "/{id}/personalInfo", method = RequestMethod.GET)
    public ResponseEntity personalInfo(@PathVariable("id") Long personUserId) {
        TodayBestVo todayBestVo = tanhuaService.personalInfo(personUserId);
        return ResponseEntity.ok(todayBestVo);
    }

    /**
     * 查询陌生人问题
     */
    @RequestMapping(value = "/strangerQuestions", method = RequestMethod.GET)
    public ResponseEntity strangerQuestions(Long userId) {
        String txt = tanhuaService.strangerQuestions(userId);
        return ResponseEntity.ok(txt);
    }

    /**
     * 回复陌生人问题
     */
    @RequestMapping(value = "/strangerQuestions", method = RequestMethod.POST)
    public ResponseEntity addStrangerQuestions(@RequestBody Map<String,String> params) {
        Long personUserId = Long.valueOf(params.get("userId"));//佳人用户id
        String reply = params.get("reply");//回复的内容
        tanhuaService.addStrangerQuestions(personUserId,reply);
        return ResponseEntity.ok(null);
    }

    /**
     * 探花推荐列表查询
     */
    @RequestMapping(value = "/cards", method = RequestMethod.GET)
    public ResponseEntity cards() {
        List<TodayBestVo> list = tanhuaService.cards();
        return ResponseEntity.ok(list);
    }


    /**
     * 探花 - 右滑
     * @param userId
     * @return
     */
    @GetMapping("/{userId}/love")
    public ResponseEntity love(@PathVariable Long userId){
        tanhuaService.love(userId, true);
        return ResponseEntity.ok(null);
    }

    /**
     * 探花 - 左滑
     * @param userId
     * @return
     */
    @GetMapping("/{userId}/unlove")
    public ResponseEntity unlove(@PathVariable Long userId){
        tanhuaService.love(userId, false);
        return ResponseEntity.ok(null);
    }

    /**
     * 搜附近
     * @param gender 性别
     * @param distance 距离 单位:米 500
     * @return
     */
    @GetMapping("/search")
    public ResponseEntity searchNearBy(String gender, Long distance){
        List<NearUserVo> list = tanhuaService.searchNearBy(gender, distance);
        return ResponseEntity.ok(list);
    }






}
